/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.class.msg')
        .controller('MsgCtrl', MsgCtrl);

    function MsgCtrl($scope,$state,$stateParams,AppUtils,MsgModel) {

        var vm = this;
        vm.disableSubmitBtn = false;
        vm.msgInfo = {};


        //var loginAccount = store.get("loginAccount");
        //loginAccount.memberId;

        vm.msgInfo.memberId = "";
        vm.msgInfo.toMemberId = $stateParams.toMemberId;

        $scope.$on('$ionicView.beforeEnter', function (event, viewData) {
            viewData.enableBack = true;
        });

        if(AppUtils.isUndefinedOrNull($stateParams.toMemberId)){
            AppUtils.showAlert("留言必要参数为空！");
            $state.go("memberMenu.parentInfo");
            vm.disableSubmitBtn = true;
        }

        $scope.saveMsgInfo = function(){
            if(AppUtils.isUndefinedOrNull(vm.msgInfo.msgContent)){
                AppUtils.showAlert("请输入留言内容！");
                return false;
            }
            MsgModel.createNewMsg(vm.msgInfo).$promise.then(function(response){
                var result = response.result;
                if(!AppUtils.isUndefinedOrNull(result) && result == 'success'){
                    AppUtils.showAlert("留言成功！");
                    AppUtils.goBack();
                }
            })
        }
    }
})();
